<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>新建病例</title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <style>

    </style>
</head>

<body>
<form class="ares-p layui-form" lay-filter="form">
    <div class="layui-form-item">
        <label class="layui-form-label">患者姓名<i class="ares-text-red">*</i></label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入姓名" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">患者编号<i class="ares-text-red">*</i></label>
        <div class="layui-input-block">
            <input name="identity" placeholder="请输入身份证号" class="layui-input" lay-verify="required|identity">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出生日期<i class="ares-text-red">*</i></label>
        <div class="layui-input-block">
            <input name="birthday" id="birthday" placeholder="请选择出生日期" class="layui-input" lay-verify="required" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">病患类型<i class="ares-text-red">*</i></label>
        <div id="patient-classify-wrap" class="layui-input-block"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div id="sex-wrap" class="layui-input-block"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">医保类型</label>
        <div id="insurance-type-wrap" class="layui-input-block"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">提交表单</button>
        </div>
    </div>
</form>

<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    layui.use(['form', 'laydate', 'utils', 'greyServices', 'widget'], function (form, laydate, utils, greyServices, widget) {

        init();

        /**
         * @author: ares
         * @date: 2021/3/25 10:00
         * @description: 提交
         */
        form.on('submit(submit)', function (data) {
            var fields = data.field,
                $this = $(data.elem),
                data = {
                    insurance_type: fields.insuranceType,
                    patient_classify: fields.patientClassify,
                    patient: {
                        name: fields.name,
                        real_name: fields.name,
                        mobile: '',
                        address: '',
                        sex: fields.sex,
                        birthday: new Date(fields.birthday).getTime(),
                        identity_card: fields.identity,
                    }
                };
            $this.prop('disabled', true).addClass('layui-btn-disabled')
            greyServices.grey_post_medical_record(data).then(function (res) {
                utils.msgSuccess(res.message)
                $this.prop('disabled', false).removeClass('layui-btn-disabled')
                utils.layerCloseAll('iframe');
                utils.ARES.event.emit('updateHomepage');
            }).catch(function (err) {
                $this.prop('disabled', false).removeClass('layui-btn-disabled')
            })
            return false;
        });

        /**
         * @author: ares
         * @date: 2021/3/25 16:33
         * @description: 生成性别选项
         */
        function renderPatientSexRadio() {
            $('#sex-wrap').empty().append(widget.createSexRadio())
        }

        /**
         * @author: ares
         * @date: 2021/3/25 16:38
         * @description: 生成医保类型
         */
        function renderInsuranceTypeRadio() {
            $('#insurance-type-wrap').empty().append(widget.createInsuranceTypeRadio())
        }

        /**
         * @author: ares
         * @date: 2021/3/25 15:26
         * @description: 渲染病患类型下拉列表
         */
        function renderPatientClassifySelect() {
            $('#patient-classify-wrap').empty().append(widget.createPatientClassifySelect('patientClassify', {verify: {'lay-verify': 'required'}}));
            form.render('select');
        }

        /**
         * @author: ares
         * @date: 2021/3/25 15:24
         * @description: 初始化
         */
        function init() {
            laydate.render({
                elem: '#birthday',
                showBottom: false,
                value: new Date()
            });
            renderPatientSexRadio();
            renderInsuranceTypeRadio();
            renderPatientClassifySelect();
            form.render();
        }

    })
</script>

</body>
</html>
